
* Set directory
cd "D:\Dropbox\Work - RA\! (2025.03.03) Final replication code for RFS"



***** Panel A (US analysis)
use "D:\Dropbox\Work - RA\D03 - EAD dummy regression\A02_EAD_with_info_ratio_crsp.dta", replace
gen con=1


	* Apply the same filter
	keep if !missing(mret,mret_t1,mret_t2-mret_t12, EAD_Dummy_t1, mret_t1xEAD_Dummy_t1)
	keep if P_t1>=1 & NYSE_decile_rank>1
	keep if inrange(year(DATE),1972,2020)

xtset PERMNO DATE
eststo clear
eststo: asreg mret mret_t1 mret_t2-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1 , fmb


***** Panel B (Datastream analysis) 
use "D:\Dropbox\Work - RA\D03 - EAD dummy regression\A02_EAD_with_info_ratio_ds.dta", replace

	* Keep obs
	keep if !missing(mret,mret_t1-mret_t12, EAD_Dummy_t1, mret_t1xEAD_Dummy_t1)

xtset id ym	
eststo: asreg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1, fmb

	
esttab using "Result_Table_3.csv", replace sfmt(%-8.0f %-8.4f) t(2) dep legend star(* 0.10 ** 0.05 *** 0.01) ///
		title($sortvar) stats(N r2_a, labels("N Obs" "Adj-R2")) indicate(`r(indicate_fe)') ///
		note("SE clustered by time")
		
		
		
***** Panel C (Datastream EQ-sort)



***** Datastream analysis based on EQ measure
use "D:\Dropbox\Work - RA\D03 - EAD dummy regression\C01_Country_EQ.dta", replace


* Keep obs
keep if !missing(mret,mret_t1-mret_t12, EAD_Dummy_t1, mret_t1xEAD_Dummy_t1)


		* Does not replicate previous results - because countries w/o EQ are dropped
		* But similar reversal / momentum / positive {mret_t1xEAD_Dummy_t1} effect (sig 1% level)
		/*
		xtset id date
		asreg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1, fmb
		*/


* In earlier sample (1991 Jan - 1992 June), sparse number of obs - even less if sorted - exclude these sample
tab date
drop if date<mdy(7,1,1992) /*4954 deleted*/
tab date if year(date)==1992 /*sufficient sample from 1992 July (2177~)*/


***** Run same regression for each EQ rank
xtset id date
tab rank1_all_in_table1
gen year=year(date)
tab year rank1_all_in_table1
tab CountryName if rank1_all_in_table1==1
tab CountryName if rank1_all_in_table1==2

eststo:asreg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1 if rank1_all_in_table1==1, fmb
eststo:asreg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1 if rank1_all_in_table1==2, fmb
	
esttab using "Result_Table_3.csv", replace sfmt(%-8.0f %-8.4f) t(2) dep legend star(* 0.10 ** 0.05 *** 0.01) ///
		title($sortvar) stats(N r2_a, labels("N Obs" "Adj-R2")) indicate(`r(indicate_fe)') ///
		note("SE clustered by time")
		


***** Test whether coefficient estimates are significantly different (Panel C, HL Diff)
log using Result_Table_3_HL_Diff.log, replace


* Create time variable [t] ranging from 1 to 342 (months)
capture drop t
gen t=year(date)*12+month(date)
tab t
replace t=t-23910
tab t


* Estimate the two models for each time period and store the difference in coefficients
forvalues period = 1/342 {
	
    * Model 1
    quietly: reg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1 if rank1_all_in_table1==1 & t==`period'
    local coef_model1_`period' = _b[mret_t1xEAD_Dummy_t1]
    * di `coef_model1_`period''

    * Model 2
    quietly: reg mret mret_t1-mret_t12 EAD_Dummy_t1 mret_t1xEAD_Dummy_t1 if rank1_all_in_table1==2 & t==`period'
    local coef_model2_`period' = _b[mret_t1xEAD_Dummy_t1]
    * di `coef_model2_`period''

    * Difference
    local coeff_diff_`period' = `coef_model1_`period'' - `coef_model2_`period''
    di `coeff_diff_`period''

}

* Sum of difference
local sum = 0 
forvalues period = 1/342 {
	local sum = `sum' + `coeff_diff_`period''
	di `sum'
}

* Sample mean
local mean = `sum'/342
di `mean'

* Sample standard dev

	* Sum of squares
	local ss = 0
	forvalues period = 1/342 {
		local ss = `ss' + (`coeff_diff_`period'' - `mean')^2
	}
	di `ss'

	* Sample STD 
	local sd = sqrt(`ss'/(342-1))
	di `sd'

local t = (`mean'/`sd')*sqrt(342)
di `t'



log close
